package com.ml.mall.mapper.category;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ml.mall.bean.req.category.CategoryDto;
import com.ml.mall.bean.req.category.CategoryQueryDto;
import com.ml.mall.bean.res.category.CategoryBriefRes;
import com.ml.mall.bean.res.category.CategoryRes;
import com.ml.mall.bean.res.category.CategorySearchRes;
import com.ml.mall.bean.res.category.CategoryTree;
import com.ml.mall.entity.category.SysACategory;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface SysACategoryMapper extends BaseMapper<SysACategory> {

    /**
     * @description    :查询目录树
     * @author         :zxm
     * @date           :2021/5/17
    **/
    List<CategoryTree> selectCategoryTree(@Param("dto") CategoryDto dto);

    /**
     * @description    :分页查询产品目录
     * @author         :zxm
     * @date           :2021/5/17
    **/
    List<CategoryRes> selectPageCategory(@Param("dto") CategoryQueryDto dto);

    /**
     * @description    :分页查询目录总数
     * @author         :zxm
     * @date           :2021/5/17
    **/
    Long countCategory(@Param("dto")CategoryQueryDto dto);

    /**
     * @description    :通过目录名称查询目录
     * @author         :zxm
     * @date           :2021/5/17
    **/
    SysACategory selectByCategoryName(@Param("categoryName") String categoryName);

    /**
     * @description    :更新父目录的子目录个数
     * @author         :zxm
     * @date           :2021/5/17
    **/
    Long updateParentCategorySonsNum(@Param("isAdd")Integer isAdd,@Param("parentId") String parentId);

    /**
     * @description    :通过categoryId查询目录
     * @author         :zxm
     * @date           :2021/5/20
    **/
    SysACategory selectByCategoryId(@Param("categoryId") String categoryId);

    /**
     * @description    :通过父目录categoryId查询其下级子目录
     * @author         :zxm
     * @date           :2021/5/27
    **/
    List<CategoryBriefRes> selectSubCategory(@Param("categoryId") String categoryId);

    /**
     * 查询全部子目录
     * @return
     */
    List<SysACategory> selectAllSub(@Param("categoryId") String categoryId);

    /**
     * @description: 目录查询总记录数
     * @author kyyang
     * @date 2021/8/28 15:04
     * @version 1.0
     */
    Integer selectCategorySearchCount(@Param("supplierId") Long supplierId,@Param("categoryId") String categoryId,@Param("categoryName") String categoryName);

    /**
     * @description: 目录查询明细
     * @author kyyang
     * @date 2021/8/28 15:37
     * @version 1.0
     */
    List<CategorySearchRes> selectCategorySearchList(@Param("companyId") Long companyId);

    /**
     * 根据根节点的原treeName和新的treeName,更新该根节点下目录树的treeName
     * @param rootCategoryId 目录树根节点id
     * @param oldRootTreeName 根节点旧treeName
     * @param newRootTreeName 根节点新treeName
     * @return
     */
    Integer updateTreeNameByRoot(@Param("rootCategoryId") String rootCategoryId, @Param("oldRootTreeName") String oldRootTreeName, @Param("newRootTreeName") String newRootTreeName);
}